package com.zhang.shopcar;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.zhang.shopcar.adapter.ShopcartExpandableListViewAdapter;
import com.zhang.shopcar.conf.Constants;
import com.zhang.shopcar.entity.GroupInfo;
import com.zhang.shopcar.entity.ProductInfo;
import com.zhang.shopcar.utils.UIUtils;
import com.zhang.shopcar.view.CustomExpandableListView;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity implements ShopcartExpandableListViewAdapter.CheckInterface, ShopcartExpandableListViewAdapter.ModifyCountInterface, View.OnClickListener {
    private static final int SHOPCARDATAFINISH = 1;//购物车数据加载完毕
    private CustomExpandableListView exListView;
    private CheckBox cb_check_all;
    private TextView tv_total_price;
    private TextView tv_delete;
    private TextView tv_go_to_pay;
    private Context context;

    private static final int CHECKALLSTATE = 1;//点击全选时的状态
    private static final int CHECKGROUPSTATE = 2;//点击组选的时候的状态

    private int mCurrentState = 2;//当前状态默认为2


    private double totalPrice = 0.00;//购买的商品总价
    private double totleJiFen = 0.00;//购买的商品总积分
    private int totalCount = 0;//购买的商品总数量

    private ShopcartExpandableListViewAdapter selva;
    private List<GroupInfo> groups = new ArrayList<>();//组元素数据列表
    private Map<String, List<ProductInfo>> children = new HashMap<>();//子元素数据列表
    private long mCustomerId;
    private long mGoodsOnLineDetailsId;

    int REQUEST_CODE = 1;
    List<Long> mDetailsIdList;//删除购物车GoodsOnLineIdDetails的集合
    private Map<Long, Integer> mShopGoodMap;
    private LinearLayout mLl_shopcar_all;
    private LinearLayout mLl_shopcar_show;
    private LinearLayout mLl_shopcar_head;

    private DecimalFormat mDf;
    private boolean mIsLogin;
    private int mLoginIndex = 0;//默认情况下的登录时从哪里的

    private boolean mIsEdit = false;
    private boolean mIsEditClick;
    private ImageView mIv_toolbar_left;
    private TextView mTxtBtn;
    private boolean mSearchdefaultaddress = true;
    private TextView mTv_heji_usually;
    private TextView mTv_heji_jifen_usually;
    private TextView mTv_totle_jifen;
    private LinearLayout mLl_shopcar;
    private static final int PULL_UP = 1;
    private int currentScrollState = 0;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            mLl_shopcar.setVisibility(View.VISIBLE);
            switch (msg.what) {
                case SHOPCARDATAFINISH:
                    if (currentScrollState == PULL_UP) {
                        selva.notifyDataSetChanged();
                    }

                    mPullToRefreshScrollView.onRefreshComplete();
                    // 这里注意,在每次设置View的Mode的后,一定要重新设置顶部，底部的显示文字。不然会出现上拉加载时显示的是下拉刷新的提示语
                    mPullToRefreshScrollView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
                    if (groups.size() != 0) {
                        mTxtBtn.setVisibility(View.VISIBLE);
                        if (mIsEdit) {
                            mTxtBtn.setText("完成");
                        } else {
                            mTxtBtn.setText("编辑");
                        }

                        mIsEditClick = UIUtils.mSp.getBoolean(Constants.ISEDITCLICK, false);
                        mLl_shopcar_all.setVisibility(View.VISIBLE);
                        mLl_shopcar_show.setVisibility(View.VISIBLE);
                        mScrollView.setVisibility(View.VISIBLE);
                        mLl_shopcar_head.setVisibility(View.GONE);
                        exListView = (CustomExpandableListView) findViewById(R.id.exListView);
                        exListView.setOverScrollMode(View.OVER_SCROLL_NEVER);
                        cb_check_all = (CheckBox) findViewById(R.id.cb_check_all);
                        mTv_heji_usually = (TextView) findViewById(R.id.tv_heji_usually);//价格
                        //积分合计
                        mTv_heji_jifen_usually = (TextView) findViewById(R.id.tv_hejijifen_usually);
                        //积分合计
                        mTv_totle_jifen = (TextView) findViewById(R.id.tv_total_jifen);

                        tv_total_price = (TextView) findViewById(R.id.tv_total_price);
                        tv_delete = (TextView) findViewById(R.id.tv_delete);


                        tv_go_to_pay = (TextView) findViewById(R.id.tv_go_to_pay);
                        mTxtBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {


                                // UIUtils.mSp.putBoolean(Constants.ISEDITCLICK,mIsEdit);
                                mIsEdit = !mIsEdit;
                                if (mIsEdit) {
                                    mTv_heji_jifen_usually.setVisibility(View.GONE);
                                    mTv_totle_jifen.setVisibility(View.GONE);
                                    tv_go_to_pay.setVisibility(View.GONE);
                                    mTv_heji_usually.setVisibility(View.GONE);
                                    tv_total_price.setVisibility(View.GONE);

                                    mTxtBtn.setText("完成");
                                    tv_delete.setVisibility(View.VISIBLE);
                                } else {
                                    mTv_heji_usually.setVisibility(View.VISIBLE);
                                    mTxtBtn.setText("编辑");
                                    tv_go_to_pay.setVisibility(View.VISIBLE);
                                    tv_delete.setVisibility(View.GONE);
                                    tv_total_price.setVisibility(View.VISIBLE);
                                    mTv_heji_jifen_usually.setVisibility(View.VISIBLE);
                                    mTv_totle_jifen.setVisibility(View.VISIBLE);


                                }
                            }
                        });


                        selva = new ShopcartExpandableListViewAdapter(groups, children, MainActivity.this);
                        selva.setCheckInterface(MainActivity.this);//关键步骤1,设置复选框接口
                        selva.setModifyCountInterface(MainActivity.this);//关键步骤2,设置数量增减接口
                        exListView.setAdapter(selva);

                        for (int i = 0; i < selva.getGroupCount(); i++) {
                            exListView.expandGroup(i);//关键步骤3,初始化时，将ExpandableListView以展开的方式呈现
                        }
                        cb_check_all.setOnClickListener(MainActivity.this);
                        tv_delete.setOnClickListener(MainActivity.this);
                        tv_go_to_pay.setOnClickListener(MainActivity.this);
                        exListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                            @Override
                            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                         /*       ProductInfo productInfo = children.get(groups.get(groupPosition).getId()).get(childPosition);
                                UIUtils.mSp.putInt(Constants.GOODSONLINEDETAILSID, (int) productInfo.getGoodsOnlineDetailsID());
                                long goodsOnLineId = productInfo.getGoodsOnlineId();
                                UIUtils.mSp.putLong(Constants.GOODSONLINEID, goodsOnLineId);
                                Log.i("ShoppiingCarActivity", goodsOnLineId + "");
                                Intent intent = new Intent(ShoppiingCarActivity.this, CommodityActivity.class);


                                startActivity(intent);*/
                                return false;
                            }
                        });
                        exListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
                            @Override
                            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                                return true;
                            }
                        });
                        calculate();
                    } else {

                        mTxtBtn.setVisibility(View.GONE);
                        mLl_shopcar_all.setVisibility(View.GONE);
                        mLl_shopcar_show.setVisibility(View.GONE);

                        mLl_shopcar_head.setVisibility(View.VISIBLE);

                        mScrollView.setVisibility(View.GONE);
                    }
                    break;
            }


            super.handleMessage(msg);
        }
    };
    private PullToRefreshScrollView mPullToRefreshScrollView;
    private ScrollView mScrollView;
    private Map mShopGoodShareMap;
    private int mIsBuy;


    /*    List<Long> goodsOnLineDetialIdList = new ArrayList<>();
        List<Integer> goodsNumList = new ArrayList<>();*/
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        RelativeLayout rl_actionBar = (RelativeLayout) findViewById(R.id.rl_actionBar);
        rl_actionBar.setVisibility(View.GONE);
        mDetailsIdList = new ArrayList<>();
        mIsLogin = UIUtils.mSp.getBoolean("isLogin", false);
        mDf = new DecimalFormat("#0.00");
        mLl_shopcar_all = (LinearLayout) findViewById(R.id.ll_shopcar_all);
        mLl_shopcar_show = (LinearLayout) findViewById(R.id.ll_shopcar_show);
        mLl_shopcar_head = (LinearLayout) findViewById(R.id.ll_shopcar_head);

        mLl_shopcar = (LinearLayout) findViewById(R.id.ll_shopcar);


        mShopGoodMap = UIUtils.getMap();
        mShopGoodShareMap = UIUtils.getGoodsShareMap();
        if (mShopGoodMap.size() != 0) {
            mShopGoodMap.clear();


            mPullToRefreshScrollView = (PullToRefreshScrollView) findViewById(R.id.pullToRefreshScrollView);
            mPullToRefreshScrollView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
            mScrollView = mPullToRefreshScrollView.getRefreshableView();
            virtualData();

            mScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
            mPullToRefreshScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ScrollView>() {
                @Override
                public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {

                    currentScrollState = PULL_UP;
                    virtualData();
                }
            });
        }
    }

        /**
         * 遵循适配器的数据列表填充原则，组元素被放在一个List中，对应的组元素下辖的子元素被放在Map中，<br>
         * 其键是组元素的Id(通常是一个唯一指定组元素身份的值)
         */

    private void virtualData() {
        if (currentScrollState == PULL_UP) {
        } else {
            mLl_shopcar_head.setVisibility(View.GONE);
            mScrollView.setVisibility(View.GONE);
        }
        mCustomerId = UIUtils.mSp.getLong(Constants.CUSTOMERID, 0);

        if (mCustomerId == 0) {
            //未登录时进入登录页
       /*
            mLoginIndex = 0;
            Intent intent = new Intent(MainActivity.this, Logining_in_Activity.class);

            startActivityForResult(intent, REQUEST_CODE);
            finish();*/
        } else {
            if (currentScrollState == PULL_UP) {
                if (children != null) {
                    children.clear();
                }
                if (groups != null) {
                    groups.clear();
                }
            }
            /*ShopCarListTask mShopCarListTask = new ShopCarListTask();
            ThreadPoolProxyFactory.createNormalThreadPoolProxy().execute(mShopCarListTask);*/
        }

    }

    //获取购物车数据
    class ShopCarListTask implements Runnable {


        @Override
        public void run() {


        /*    try {

                ShopCarListProtocol shopCarListProtocol = new ShopCarListProtocol();
                ShopCarListBean shopCarListBean = shopCarListProtocol.lodateDataNoCatch(mCustomerId);
                if (shopCarListBean != null) {
                    if (shopCarListBean.getIsSuccess()) {
                        List<ShopCarListBean.ShopBean> mShopBeanList = shopCarListBean.getList();

                        if (mShopBeanList.size() != 0) {

                            ShopCarListBean.ShopBean shopBean = null;
                            for (int i = 0; i < mShopBeanList.size(); i++) {
                                shopBean = mShopBeanList.get(i);
                                GroupInfo groupInfo = new GroupInfo();

                                groupInfo.setName(shopBean.getShopName());
                                groupInfo.setId(shopBean.getShopID() + "");

                                groups.add(groupInfo);

                                ProductInfo childProInfo = null;
                                List<ProductInfo> childlist = new ArrayList<>();
                                ShopCarListBean.ShopBean.GoodsBean goodsBean = null;
                                List<ShopCarListBean.ShopBean.GoodsBean> goodsBeanList = shopBean.getGoods();


                                for (int j = 0; j < shopBean.getGoodsNumber(); j++) {
                                    childProInfo = new ProductInfo();
                                    goodsBean = goodsBeanList.get(j);
                                    childProInfo.setName(goodsBean.getGoodName());
                                    childProInfo.setDesc("颜色:" + goodsBean.getGoodsColor() + "  尺寸:" + goodsBean.getGoodsSize());
                                    childProInfo.setGoodsOnlineDetailsID(goodsBean.getGoodsOnlineDetailsID());
                                    childProInfo.setPVValue(goodsBean.getPVValue());
                                    childProInfo.setPrice(goodsBean.getGoodPrice());
                                    childProInfo.setBussine(goodsBean.getShopName());
                                    childProInfo.setNum(goodsBean.getCurrentCount());
                                    childProInfo.setCount(goodsBean.getCurrentCount());//默认产品的个数
                                    childProInfo.setImageUrl(goodsBean.getImageUrl());
                                    childProInfo.setGoodsOnlineId(goodsBean.getGoodsOnlineID());
                                    childProInfo.setShares(goodsBean.isShares());
                                    childProInfo.setChooseShares(goodsBean.isBuy());
                                    childProInfo.setSharesPrice(goodsBean.getSharesPrice());
                                    childProInfo.setChoosed(goodsBean.isBuy());//默认第一次与股票商品状态相同
                                    childlist.add(childProInfo);
                                }
                                children.put(shopBean.getShopID() + "", childlist);

                            }

                        }

                    } else {

                        return;


                    }
                } else {
                    UIUtils.postTaskSafely(new Runnable() {
                        @Override
                        public void run() {
                            UIUtils.showToast(MainActivity.this, "网络不可用");
                            return;
                        }
                    });
                }


            } catch (IOException e) {
                e.printStackTrace();
            }

            mHandler.obtainMessage(SHOPCARDATAFINISH).sendToTarget();*/
        }
    }

    @Override
    public void onClick(View v) {
        AlertDialog alert;
        switch (v.getId()) {
            case R.id.cb_check_all:
                doCheckAll();
                break;
            case R.id.tv_go_to_pay:
                try {
                    if (totalCount == 0) {
                        UIUtils.showToast(MainActivity.this, "请选择要支付的商品");
                        return;
                    }
                } catch (NullPointerException e) {
                    e.printStackTrace();
                    UIUtils.showToast(MainActivity.this, "请选择要支付的商品");
                    return;
                }
                if (mIsLogin) {//进入提交订单页
                  /*  //http://192.168.1.44/Cart/CommitOrderList/1?gid=0&count=1&ids=308,318&counts=2,1
                    Intent intent = new Intent(MainActivity.this, ConfirmingToBuyActivity.class);
                    UIUtils.mSp.putInt(Constants.ADDRESSID, 0);//确认订单页 地址查找全部 查找默认地址
                    UIUtils.mSp.putBoolean(Constants.SEARCHDEFAULTADDRESS, mSearchdefaultaddress);//进入确认订单页查找默认地址状态判定
                    UIUtils.mSp.putInt(Constants.CURRSTATES, 2);
                    startActivity(intent);
                    finish();*/
                } else {
//                            未登录去登录
                 /*   Intent intent = new Intent(MainActivity.this, Logining_in_Activity.class);
                    startActivityForResult(intent, REQUEST_CODE);*/

                }


                break;
            case R.id.tv_delete:
                try {
                    if (totalCount == 0) {
                        UIUtils.showToast(MainActivity.this, "请选择要移除的商品");
                        return;
                    }
                } catch (NullPointerException e) {
                    e.printStackTrace();
                    UIUtils.showToast(MainActivity.this, "请选择要移除的商品");
                    return;
                }

                alert = new AlertDialog.Builder(MainActivity.this).create();
                alert.setTitle("操作提示");
                alert.setMessage("您确定要将这些商品从购物车中移除吗？");
                alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
                alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        doDelete();
                    }
                });
                alert.show();
                break;


            default:
                break;
        }
    }


    //登录之后返回结果
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {


        if (requestCode == REQUEST_CODE) {
            if (resultCode == 2) {
                Bundle extras = intent.getExtras();
                if (extras != null) {
                    mIsLogin = extras.getBoolean("isLogin");
                    UIUtils.mSp.putBoolean("isLogin", mIsLogin);

                    if (mIsLogin) {
                       /* if (mLoginIndex == 1) {
                            Intent ConfirmingIntent = new Intent(MainActivity.this, ConfirmingToBuyActivity.class);
                            UIUtils.mSp.putInt(Constants.CURRSTATES, 1);

                            startActivity(ConfirmingIntent);
                            finish();
                        } else {


                            return;
                        }*/

                    }
                }
            }

            super.onActivityResult(requestCode, resultCode, intent);
        }
    }


    /**
     * 删除操作<br>
     * 1.不要边遍历边删除，容易出现数组越界的情况<br>
     * 2.现将要删除的对象放进相应的列表容器中，待遍历完后，以removeAll的方式进行删除
     * 直接重新访问网络数据 ,在list里不执行操作了
     */
    protected void doDelete() {

        List<GroupInfo> toBeDeleteGroups = new ArrayList<>();//待删除的组元素列表
        for (int i = 0; i < groups.size(); i++) {
            GroupInfo group = groups.get(i);
            if (group.isChoosed()) {
                toBeDeleteGroups.add(group);
            }
            List<ProductInfo> toBeDeleteProducts = new ArrayList<>();//待删除的子元素列表
            List<ProductInfo> childs = children.get(group.getId());
            for (int j = 0; j < childs.size(); j++) {
                if (childs.get(j).isChoosed()) {
                    toBeDeleteProducts.add(childs.get(j));
                    mGoodsOnLineDetailsId = childs.get(j).getGoodsOnlineDetailsID();
                    mDetailsIdList.add(mGoodsOnLineDetailsId);
                    // Log.i("ShoppiingCarActivity","aaaaaaaaaaaaaaaaaa"+mGoodsOnLineDetailsId+"");

                }

            }
            childs.removeAll(toBeDeleteProducts);


        }


        groups.removeAll(toBeDeleteGroups);
        //   selva.notifyDataSetChanged();


        String goodsDetailsIdAllId = UIUtils.getDetailsIdForList(mDetailsIdList);
        Map<String, Object> map = new HashMap<>();

        map.put("customerID", mCustomerId);
        map.put("goodsOnlineDetailsIds", goodsDetailsIdAllId);

      //  String keyWords = Constants.URLS.DELETESHOPSF;

      /*  ComicServer.deleteShopCar(infoMap, new RxSubscribe<BaseBean>(ShoppiingCarActivity.this) {
            @Override
            protected void _onNext(BaseBean baseBean) {


            }

            @Override
            protected void _onError(String message) {
                UIUtils.showToast(MainActivity.this, message);
            }
        });*/

        calculate();


    }


    @Override
    public void doIncrease(int groupPosition, int childPosition, View showCountView, boolean isChecked) {


        ProductInfo product = (ProductInfo) selva.getChild(groupPosition, childPosition);
        product.setChoosed(true);
        checkChild(groupPosition, childPosition, true);
        int currentCount = product.getCount();
        currentCount++;
        if (currentCount >= 99) {
            currentCount = 99;
            UIUtils.showToast(MainActivity.this, "最多只能添加99个");
        }
        product.setCount(currentCount);
        ((TextView) showCountView).setText(currentCount + "");

        selva.notifyDataSetChanged();
        calculate();
    }

    @Override
    public void doDecrease(int groupPosition, int childPosition, View showCountView, boolean isChecked) {


        ProductInfo product = (ProductInfo) selva.getChild(groupPosition, childPosition);
        product.setChoosed(true);
        checkChild(groupPosition, childPosition, true);
        int currentCount = product.getCount();
        currentCount--;
        if (currentCount <= 1) {
            currentCount = 1;
            UIUtils.showToast(MainActivity.this, "最少要一件商品");
        }
        product.setCount(currentCount);
        ((TextView) showCountView).setText(currentCount + "");

        selva.notifyDataSetChanged();
        calculate();
    }

    @Override
    public void checkGroup(int groupPosition, boolean isChecked) {
        boolean allGroupSameState = true;
        GroupInfo group = groups.get(groupPosition);
        List<ProductInfo> childs = children.get(group.getId());
        for (int i = 0; i < childs.size(); i++) {
            childs.get(i).setChoosed(isChecked);
            if (!isChecked) {
                childs.get(i).setChooseShares(isChecked);
            }
        }
        if (mCurrentState == CHECKGROUPSTATE) {//当状态为2 也就是不是从全选处点击的时候回生效
            for (int j = 0; j < groups.size(); j++) {
                if (groups.get(j).isChoosed() != isChecked) {
                    allGroupSameState = false;

                }
            }
            if (allGroupSameState) {
                cb_check_all.setChecked(isChecked);
            } else {
                cb_check_all.setChecked(false);
            }
        }


        selva.notifyDataSetChanged();
        calculate();
    }

    @Override
    public void checkChild(int groupPosition, int childPosiTion, boolean isChecked) {
        boolean allChildSameState = true;//判断改组下面的所有子元素是否是同一种状态
        boolean allGroupSameState = true;
        GroupInfo group = groups.get(groupPosition);
        List<ProductInfo> childs = children.get(group.getId());
        for (int i = 0; i < childs.size(); i++) {
            if (childs.get(i).isChoosed() != isChecked) {

                allChildSameState = false;
                break;
            }
        }

        if (allChildSameState) {

            group.setChoosed(isChecked);//如果所有子元素状态相同，那么对应的组元素被设为这种统一状态

            //遍历所有的组元素,每个组元素的状态不同时,就返回false
            for (int j = 0; j < groups.size(); j++) {
                if (groups.get(j).isChoosed() != isChecked) {
                    allGroupSameState = false;
                    break;
                }
            }
            //根据组元素的状态来改变cb_all的状态
            if (allGroupSameState) {
                cb_check_all.setChecked(isChecked);
            } else {
                cb_check_all.setChecked(false);
            }

        } else {
            group.setChoosed(false);//否则，组元素一律设置为未选中状态

            //这里是判断=一个选中了一个没选中的时候cb_all的状态
            for (int j = 0; j < groups.size(); j++) {
                if (groups.get(j).isChoosed() != isChecked) {
                    allGroupSameState = false;
                    break;
                }
            }
            if (allGroupSameState) {
                cb_check_all.setChecked(isChecked);
            } else {
                cb_check_all.setChecked(false);
            }

        }
        selva.notifyDataSetChanged();
        calculate();

    }

    /**
     * 全选与反选
     */
    private void doCheckAll() {

        for (int i = 0; i < groups.size(); i++) {
            mCurrentState = CHECKALLSTATE;//点击全选会走全选时组group的状态
            groups.get(i).setChoosed(cb_check_all.isChecked());
            checkGroup(i, cb_check_all.isChecked());
        }

        selva.notifyDataSetChanged();
    }

    int mAllCount;

    /**
     * 统计操作<br>
     * 1.先清空全局计数器<br>
     * 2.遍历所有子元素，只要是被选中状态的，就进行相关的计算操作<br>
     * 3.给底部的textView进行数据填充
     */
    private void calculate() {
        totalCount = 0;
        totalPrice = 0.00;
        totleJiFen = 0.00;
        mAllCount = 0;
        for (int i = 0; i < groups.size(); i++) {

            GroupInfo group = groups.get(i);
            List<ProductInfo> childs = children.get(group.getId());

            for (int j = 0; j < childs.size(); j++) {
                ProductInfo product = childs.get(j);
                if (product.isChoosed()) {

                    mShopGoodMap.put(product.getGoodsOnlineDetailsID(), product.getCount());
                    mAllCount += product.getCount();
                    totalCount++;

                    totleJiFen += product.getPVValue() * product.getCount();
                    mCurrentState = 2;//将状态改变为点击组cb的状态
                } else {

                    mShopGoodMap.remove(product.getGoodsOnlineDetailsID());
                }





             /*   product.setGoodsOnLineIdList(goodsOnLineDetialIdList);
                product.setGoodsnumberList(good);*/
            }
        }

        DecimalFormat df = new DecimalFormat("#0.00");
        tv_total_price.setText("￥" + df.format(totalPrice));
        mTv_totle_jifen.setText(df.format(totleJiFen));
        tv_go_to_pay.setText("去支付(" + mAllCount + ")");

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
          /*  getMenuInflater().inflate(R.menu.menu_main,menu);*/

        return super.onCreateOptionsMenu(menu);
    }


    @Override
    public void onResume() {
        boolean isPush = UIUtils.mSp.getBoolean(Constants.SHOPCARPUSH, false);//是否进入付款页面,进入之后购物车商品就会消失

        if (isPush) {
            if (mShopGoodMap.size() != 0) {
                mShopGoodMap.clear();

            }
            if (mShopGoodShareMap.size() != 0) {
                mShopGoodShareMap.clear();

            }

        }
        super.onResume();
    }
}
